package com.qk.filter;


import jakarta.servlet.*;

import java.io.IOException;

//@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {
    //初始化-web服务器启动的时候执行，只执行一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
//        Filter.super.init(filterConfig);
        System.out.println("DemoFilter init");
    }

    //销毁-web服务器停止的时候执行，只执行一次
    @Override
    public void destroy() {
//        Filter.super.destroy();
        System.out.println("DemoFilter destroy");

    }

    //每一次拦截到请求，都会执行该方法
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("DemoFilter");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
